<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>mutation传递参数</title>
  <link rel="stylesheet" href="../css/base.css">
  <script src="../js/vue.js"></script>
  <script src="../js/vue_router.js"></script>
  <script src="../js/vuex.js"></script>
  <style>
    .cls {
      width: 50%;
      margin: 200px auto;
      border: 2px solid red;
    }

    .cls>input {
      margin: 100px 50px;
      cursor: pointer;
    }
  </style>
</head>
<!-- 
  mutations传递参数
 -->

<body>
  <div id="app">
    <div class="cls">
      <h1>观看数据的改变了{{count}}</h1>
      <input type="button" @click="handle()" value="点击可以发生改变了">
    </div>
  </div>
</body>
<script>
  "use strict";
  const store = new Vuex.Store({
    state: {
      count: 0
    },
    mutations: {
      addN(state, step) {
        state.count += step;
      }
    }
  });
  const vm = new Vue({
    el: "#app",
    data() {
      return {};
    },
    store,
    methods: {
      handle() {
        this.$store.commit("addN", 3);
      }
    },
    computed: {
      ...Vuex.mapState(["count"])
    }
  });
</script>

</html>